﻿using Prism.Ioc;
using Prism.Modularity;
using Prism.Unity;
using System.Configuration;
using System.Data;
using System.Windows;
using Wpf_ModuleA;
using WpfApp_PrismModule.Views;

namespace WpfApp_PrismModule
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            //第一种加载方式
            moduleCatalog.AddModule<ModuleA>();

            // 第二种方式
           
            //Type type = typeof(ModuleA);
            ////string _s = type.AssemblyQualifiedName;
            //moduleCatalog.AddModule(new ModuleInfo
            //{
            //    ModuleName = type.Name,
            //    ModuleType = type.AssemblyQualifiedName,
            //    // 标记Module按需加载
            //    InitializationMode = InitializationMode.OnDemand
            //});
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            //通过App.config加载模块
            //return new ConfigurationModuleCatalog();

            //通过xml加载，必须要要引用加载的程序集，否则会报如下异常
            //Prism.Modularity.ModuleTypeLoaderNotFoundException:“There is currently no moduleTypeLoader in the ModuleManager that can retrieve the specified module.”
            //return new XamlModuleCatalog(".\\ModuleConfig.xml");

            //通过目录（推荐）
            return new DirectoryModuleCatalog()
            {
                //配置将在扫描的目录
                ModulePath = ".\\ModulePath"
            };
        }
    }

}
